package sdk;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import model.Info;

public class InfoSDK {
    private Client client;

    public InfoSDK(Client client) {
        this.client = client;
    }

    public Map<String, Object> getDeviceSettingOnlineCardInfo(Info.GetDeviceSettingOnlineCardInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceSettingOnlineCardInfo", getParamsf);
    }

    public Map<String, Object> deviceSaveMode(Info.DeviceSaveModeReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> combinedParams = new HashMap<>();
        if (req != null) {
            Class<?> clazz = req.getClass();
            for (Field field : clazz.getDeclaredFields()) {
                field.setAccessible(true);
                try {
                    String fieldName = field.getName();
                    Object fieldValue = field.get(req);
                    combinedParams.put(fieldName, fieldValue);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Failed to access field in deviceSaveMode ", e);
                }
            }
        }
        Map<String, Object> postParams = buildClient.buildPostParam(combinedParams);
        return client.post("/open/device/saveMode", postParams);
    }

    public Map<String, Object> getDeviceModeTimeInfo(Info.GetDeviceModeTimeInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num); 
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceModeTimeInfo", getParamsf);
    }

    public Map<String, Object> getDeviceModeTime1Info(Info.GetDeviceModeTime1InfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num); 
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceModeTime1Info", getParamsf);
    }

    public Map<String, Object> getDeviceSettingCoinInfo(Info.GetDeviceSettingCoinInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num); 
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceSettingCoinInfo", getParamsf);
    }

    public Map<String, Object> findMultiDevices(Info.FindMultiDevicesReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> combinedParams = new HashMap<>();
        if (req != null) {
            Class<?> clazz = req.getClass();
            for (Field field : clazz.getDeclaredFields()) {
                field.setAccessible(true);
                try {
                    String fieldName = field.getName();
                    Object fieldValue = field.get(req);
                    combinedParams.put(fieldName, fieldValue);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Failed to access field in findMultiDevices ", e);
                }
            }
        }
        Map<String, Object> postParams = buildClient.buildPostParam(combinedParams);
        return client.post("/open/device/findMultiDevices", postParams);
    }

    public Map<String, Object> deviceAdd(Info.DeviceAddReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> combinedParams = new HashMap<>();
        if (req != null) {
            Class<?> clazz = req.getClass();
            for (Field field : clazz.getDeclaredFields()) {
                field.setAccessible(true);
                try {
                    String fieldName = field.getName();
                    Object fieldValue = field.get(req);
                    combinedParams.put(fieldName, fieldValue);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException("Failed to access field in deviceAdd ", e);
                }
            }
        }
        Map<String, Object> postParams = buildClient.buildPostParam(combinedParams);
        return client.post("/open/device/add", postParams);
    }

    public Map<String, Object> getDeviceModeWorkInfo(Info.GetDeviceModeWorkInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num); 
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceModeWorkInfo", getParamsf);
    }

    public Map<String, Object> getDeviceModeWork1Info(Info.GetDeviceModeWork1InfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num); 
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceModeWork1Info", getParamsf);
    }

    public Map<String, Object> getDeviceModePowerInfo(Info.GetDeviceModePowerInfo req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceModePowerInfo", getParamsf);
    }

    public Map<String, Object> getDeviceModePower1Info(Info.GetDeviceModePower1Info req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);  
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceModePower1Info", getParamsf);
    }

    public Map<String, Object> findList(Info.DeviceFindListReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        getParams.put("iot_phone",req.iot_phone );
        getParams.put("device_type",req.device_type );
        getParams.put("page_size", req.page_size);
        getParams.put("page", req.page);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/findList", getParamsf);
    }

    public Map<String, Object> deviceDel(Info.DeviceDelReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/del", getParamsf);
    }

    public Map<String, Object> deviceGetMode(Info.DeviceGetModeReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getMode", getParamsf);
    }

    public Map<String, Object> getDeviceSettingUserInfo(Info.GetDeviceSettingUserInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceSettingUserInfo", getParamsf);
    }

    public Map<String, Object> getDeviceSettingNotDisturbInfo(Info.GetDeviceSettingNotDisturbInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceSettingNotDisturbInfo", getParamsf);
    }

    public Map<String, Object> deviceFindOne(Info.DeviceFindOneReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num", req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/findOne", getParamsf);
    }

    public Map<String, Object> getDeviceSettingOfflineCardInfo(Info.GetDeviceSettingOfflineCardInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num",  req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceSettingOfflineCardInfo", getParamsf);
    }

    public Map<String, Object> getDeviceSettingSafetyInfo(Info.GetDeviceSettingSafetyInfoReq req) {
        String appId = client.getAppId();
        String appSecret = client.getAppSecret();
        BuildClientSDK buildClient = new BuildClientSDK(appId,appSecret);
        Map<String, Object> getParams = new TreeMap<>();
        getParams.put("device_num",  req.device_num);
        Map<String, Object> getParamsf = buildClient.buildGetParam(getParams);
        return client.get("/open/device/getDeviceSettingSafetyInfo", getParamsf);
    }
}